package com.deft.design.abstracts.matter;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zdl
 * @description
 * @date 2022-04-18
 **/
@Slf4j
public class Oracle {

    private final Map<Integer, Object> dataMap = new ConcurrentHashMap<>();

    private static Integer num = 1;

    public void insert(String str) {
        dataMap.put(num, str);
        log.info("Oracle数据库新增了一条数据：{} id:{}", str, num);
        num++;
    }

    public void delete(Integer id) {
        log.info("Oracle数据库删除了id:{}的数据", id);
        dataMap.remove(id);
    }

    public void update(Integer id, String str) {
        Object o = dataMap.get(id);
        if (o == null) {
            return;
        }
        dataMap.put(id, str);
        log.info("Oracle修改了id：{}的数据：{}", id, str);
    }

    public String select(Integer id) {
        Object obj = dataMap.get(id);
        log.info("Oracle查询到id为：{}的数据：{}", id, obj);
        if (obj == null) {
            return null;
        }
        return obj.toString();
    }
}
